import math
import torch
import torch.nn as nn
import numpy as np

class Net(nn.Module):
    def __init__(self, n_filter=65, kernel_size=60, stride=1, number_class=4, filter_row=2):
        super(Net, self).__init__()
        self.conv = nn.Conv1d(in_channels=1, out_channels=n_filter, kernel_size=(filter_row, kernel_size), stride=stride)
        self.max_pool = nn.AdaptiveMaxPool2d(1)  # 二维池化，结果一样的，因为输入必须是4维的，对维度扩充了就变成二维的了
        self.n_filter = n_filter
        self.fc = nn.Sequential(nn.Linear(n_filter, 128, bias=True),
            nn.BatchNorm1d(128),
            nn.ReLU(inplace=True),
            nn.Linear(128, number_class, bias=True)
        )

    def forward(self, x):

        batch_size = x.size(0)
        x = x.reshape(batch_size, 1, 1, -1)
        x = x.float()
        x = self.conv(x)
        x = self.max_pool(x)
        x = x.view(batch_size, -1)
        out = self.fc(x)
        return out
